package com.example.venue_reservation_service.controller;

import com.example.venue_reservation_service.dto.*;
import com.example.venue_reservation_service.mapper.ReservationMapper;
import com.example.venue_reservation_service.service.ReservationService;
import com.example.venue_reservation_service.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/reservation")
@Api("预约操作管理")
@CrossOrigin
public class ReservationController {

    @Resource
    private ReservationService reservationService;

    @Resource
    private ReservationMapper reservationMapper;

    @GetMapping("/list")
    public Result userList(@RequestParam("userId") Integer userId){
        return Result.ok(reservationMapper.selectByUserId(userId)).message("查询成功");
    }

    @ApiOperation("添加预约信息")
    @PostMapping("/create")
    public Result create(@RequestBody RAddDTO dto){
        return reservationService.addReservation(dto);
    }

    @ApiOperation("查询预约订单信息")
    @PostMapping("/query")
    public Result query(@RequestBody ReservationDTO dto){
        return reservationService.getReservations(dto);
    }

    @ApiOperation("取消订单")
    @GetMapping("/cancel")
    public Result cancel(@RequestParam("reservationId") Integer reservationId){
        return reservationService.cancelReservation(reservationId);
    }

    @ApiOperation("对预约订单进行签到")
    @PostMapping("/signIn")
    public Result signIn(@RequestBody SignInDTO dto){
        return reservationService.signInReservation(dto);
    }

    @ApiOperation("管理员查看详细的预约信息")
    @GetMapping("/detail")
    public Result detail(@RequestParam("reservationId") Integer id){
        return reservationService.queryDetail(id);
    }

    @ApiOperation("移除预约信息（单条）")
    @PostMapping("/single")
    public Result remove(@RequestParam("userId") Integer userId, @RequestParam("reservationId") Integer id){
        return reservationService.removeSingle(userId, id);
    }

    @ApiOperation("移除预约信息（批量）")
    @PostMapping("/remove")
    public Result remove(@RequestBody DelDTO dto){
        return reservationService.removeBatch(dto);
    }

    @ApiOperation("获取预约数据")
    @GetMapping("/data")
    public Result data(@RequestParam("time") String time){
        return reservationService.exportData(time);
    }

    @ApiOperation("导出用户预约记录")
    @GetMapping("/excel")
    public void excel(@RequestParam(value = "id", required = false) Integer userId, HttpServletResponse response){
        reservationService.exportExcel(response, userId);
    }

    @ApiOperation("全年账单数据导出")
    @GetMapping("/payment")
    public void exportPayments(HttpServletResponse response, @RequestParam(name = "year", defaultValue = "current") String yearFilter) {
        // 调用服务层导出方法
        reservationService.exportPayments(response, yearFilter);
    }

    @ApiOperation("智能场地推荐")
    @GetMapping("/recommend")
    public Result recommend(@RequestParam("userId") Integer userId){
        return reservationService.recommend(userId);
    }

}
